<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>html</title>
</head>
<body>
<script>
    //1.创建XMLHttpRequest实例
    let xhr = new XMLHttpRequest();
    console.log('readyState',xhr.readyState)
    //设置了响应体的类型是json
    xhr.responseType = 'json';
    //2.注册当状态变化时回调函数
    xhr.onreadystatechange = function(){
        console.log('readyState',xhr.readyState)
        if(xhr.readyState===xhr.DONE && (/^2\d{2}$/.test(xhr.status))){
            //获取所有的响应头
            console.log(xhr.getAllResponseHeaders())
            //获取响应体
            console.log(xhr.response);
        }
    }
    //2.打开连接  表示对http://localhost:3000/users发送POST请求，异步方式
    xhr.open('GET','/users',true);
    xhr.send();
</script>
</body>
</html>